﻿using System;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //Drone
    public class Drone : StarShip
    {
        //constructor
        public Drone(SVGame game, Player owner, int engines, StarSystem origin)
            : base(game, owner, engines, 0, origin)
        {
        }

        //Name
        public override string Name
        {
            get
            {
                return "Drone";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "Drones strike their targets and explode, destroying themselves in the process, and possibly the target. If the target has a lower Engine rating than the Drone, it is destroyed. Otherwise, there is still a chance it is destroyed, based on the engine difference between the Drone and its target.";
            }
        }

        //Type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.Drone;
            }        
        }

        //Attacks adjacent by default
        public override bool AttackAdjacentDefault
        {
            get
            {
                return true;
            }
        }

        //additional order types
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.Defend:
                case OrderType.DefendPoint:
                case OrderType.TargetStarShip:
                case OrderType.AttackAdjacent:
                    return true;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }

        //can it target a specific StarShip?
        public override bool CanTargetStarShip(StarShip ship, bool respectAlliance)
        {
            if (respectAlliance)
                return !Owner.FriendlyTo(ship.Owner);
            else
                return !ship.OwnedByCurrentPlayer;
        }

        //Can destroy anything
        public override bool CanDestroy(StarShip target)
        {
            return true;
        }

        //private members

        //Attack a StarShip
        protected override void TargetAdjacentStarShip(StarShip target)
        {
            int droneDestroy;
            if (target.Engines == 0)
                droneDestroy = 100;
            else
                droneDestroy = (Engines * 100) / target.Engines;
            if (SVGame.RNG.Next(100) < droneDestroy)
            {
                if (target.ShipType == StarShipType.BattleStation)
                    target.Damage(1, false);
                else
                    Game.DestroyStarShip(target);
            }
            Game.DestroyStarShip(this);
        }
    }
}
